﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Calibration.CUiCalibrationNewSetDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Calibration.Resources;
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.Calibration;

public class CUiCalibrationNewSetDlg : TxWindow, IComponentConnector
{
  private CApCalibrationSetsModel _CalibrationSetsModel;
  private bool _WindowResult = true;
  internal TxObjEditBoxControl CalibrationSetRobotOrDevice;
  internal TextBox CalibrationSetName;
  internal TextBox CalibrationSetDescription;
  internal Button OKButton;
  private bool _contentLoaded;

  public bool WindowResult
  {
    get => this._WindowResult;
    set => this._WindowResult = value;
  }

  public CUiCalibrationNewSetDlg(CApCalibrationSetsModel csm)
  {
    this.InitializeComponent();
    this._CalibrationSetsModel = csm;
    this.SemiModal = true;
    this.CalibrationSetRobotOrDevice.ValidatorType = (TxValidatorType) 8;
    this.CalibrationSetRobotOrDevice.SetPickProviders(new TxPickProvider[2]
    {
      null,
      (TxPickProvider) 1
    });
    this.CalibrationSetRobotOrDevice.ListenToPick = true;
    this.CalibrationSetRobotOrDevice.Focus();
    this.CalibrationSetRobotOrDevice.Select();
    this.CalibrationSetName.GotFocus += new RoutedEventHandler(this.CalibrationSetName_GotFocus);
    this.CalibrationSetDescription.GotFocus += new RoutedEventHandler(this.CalibrationSetDescription_GotFocus);
    this.WindowResult = false;
  }

  private bool Validate()
  {
    return !this.CalibrationSetName.Text.Equals("") && this.CalibrationSetRobotOrDevice.IsValid();
  }

  private void CalibrationSetName_GotFocus(object sender, RoutedEventArgs e)
  {
    this.CalibrationSetRobotOrDevice.LoseFocus();
    this.GenerateCalibrationSetName();
    this.OKButton.IsEnabled = this.Validate();
  }

  private void CalibrationSetDescription_GotFocus(object sender, RoutedEventArgs e)
  {
    this.CalibrationSetRobotOrDevice.LoseFocus();
    this.GenerateCalibrationSetName();
    this.OKButton.IsEnabled = this.Validate();
  }

  private void OKButton_Click(object sender, RoutedEventArgs e)
  {
    if (!this.Validate())
      return;
    this.WindowResult = true;
    ((Window) this).Close();
  }

  private void CancelButton_Click(object sender, RoutedEventArgs e)
  {
    this.WindowResult = false;
    ((Window) this).Close();
  }

  private void CalibrationSetName_KeyUp(object sender, KeyEventArgs e)
  {
    this.OKButton.IsEnabled = this.Validate();
  }

  private void CalibrationSetRobotOrDevice_KeyUp(object sender, EventArgs e)
  {
    this.OKButton.IsEnabled = this.Validate();
  }

  private void CalibrationSetRobotOrDevice_Picked(
    object sender,
    TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.OKButton.IsEnabled = this.Validate();
  }

  private void GenerateCalibrationSetName()
  {
    if (!this.CalibrationSetName.Text.Equals("") || !this.CalibrationSetRobotOrDevice.IsValid())
      return;
    int num1 = 1;
    int num2 = 0;
    string CalibrationSetName;
    do
    {
      CalibrationSetName = $"{this.CalibrationSetRobotOrDevice.Text} {CalibrationResources.CALIBRATION_NEW_CALIBRATION_SET_DEFAULT_NAME} {num1.ToString()}";
      ++num2;
      ++num1;
    }
    while (!this._CalibrationSetsModel.CheckUniqueName(CalibrationSetName) && num2 < 100);
    this.CalibrationSetName.Text = CalibrationSetName;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/calibration/cuicalibrationnewsetdlg.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.CalibrationSetRobotOrDevice = (TxObjEditBoxControl) target;
        ((UIElement) this.CalibrationSetRobotOrDevice).KeyUp += new KeyEventHandler(this.CalibrationSetName_KeyUp);
        this.CalibrationSetRobotOrDevice.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.CalibrationSetRobotOrDevice_Picked);
        break;
      case 2:
        this.CalibrationSetName = (TextBox) target;
        this.CalibrationSetName.KeyUp += new KeyEventHandler(this.CalibrationSetName_KeyUp);
        break;
      case 3:
        this.CalibrationSetDescription = (TextBox) target;
        break;
      case 4:
        this.OKButton = (Button) target;
        this.OKButton.Click += new RoutedEventHandler(this.OKButton_Click);
        break;
      case 5:
        ((ButtonBase) target).Click += new RoutedEventHandler(this.CancelButton_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
